Telegram Group & Telegram Channel
Inverts a dictionary with non-unique hashable values.

👉Create a collections.defaultdict with list as the default value for each key.

👉Use dictionary.items() in combination with a loop to map the values of the dictionary to keys using dict.append().

👉Use dict() to convert the collections.defaultdict to a regular dictionary.

CODE:

from collections import defaultdict

def collect_dictionary(obj):
inv_obj = defaultdict(list)
for key, value in obj.items():
inv_obj[value].append(key)
return dict(inv_obj)

Example:

ages = {
'Peter': 10,
'Isabel': 10,
'Anna': 9,
}
collect_dictionary(ages)

Output: { 10: ['Peter', 'Isabel'], 9: ['Anna'] }

Share and Support
@Python_Codes



tg-me.com/python_codes/220
Create:
Last Update:

Inverts a dictionary with non-unique hashable values.

👉Create a collections.defaultdict with list as the default value for each key.

👉Use dictionary.items() in combination with a loop to map the values of the dictionary to keys using dict.append().

👉Use dict() to convert the collections.defaultdict to a regular dictionary.

CODE:

from collections import defaultdict

def collect_dictionary(obj):
inv_obj = defaultdict(list)
for key, value in obj.items():
inv_obj[value].append(key)
return dict(inv_obj)

Example:

ages = {
'Peter': 10,
'Isabel': 10,
'Anna': 9,
}
collect_dictionary(ages)

Output: { 10: ['Peter', 'Isabel'], 9: ['Anna'] }

Share and Support
@Python_Codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/220

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

Look for Channels Online

You guessed it – the internet is your friend. A good place to start looking for Telegram channels is Reddit. This is one of the biggest sites on the internet, with millions of communities, including those from Telegram.Then, you can search one of the many dedicated websites for Telegram channel searching. One of them is telegram-group.com. This website has many categories and a really simple user interface. Another great site is telegram channels.me. It has even more channels than the previous one, and an even better user experience.These are just some of the many available websites. You can look them up online if you’re not satisfied with these two. All of these sites list only public channels. If you want to join a private channel, you’ll have to ask one of its members to invite you.

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

Python Codes from it


Telegram Python Codes
FROM USA